package com.ExcelServer.controller;

import com.ExcelServer.common.Result;
import com.ExcelServer.mapper.ExcelCreateInfoMapper;
import com.ExcelServer.pojo.entity.ExcelCreateInfo;
import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/se/excel/util")
@Tag(name = "util",description = "util")
@Hidden
public class UtilController {

    @Autowired
    ExcelCreateInfoMapper excelCreateInfoMapper;


    @Operation(summary = "直接获取query请求体",description = "直接获取query请求体")
    @GetMapping("/query/{tableId}")
    public Result<Map<String,String>> getTableHeaderQuery(@PathVariable("tableId") String tableId) throws Exception{
        ExcelCreateInfo excelCreateInfo = excelCreateInfoMapper.selectById(tableId);
        String property = (String) excelCreateInfo.getProperty();

        Map<String,String> parse = (Map<String,String>) JSON.parse(property);
        for (Map.Entry<String,String> entry : parse.entrySet()) {
            entry.setValue("");
        }
        return Result.success(parse);
    }

    @Operation(summary = "获取query请求体映射内容含义",description = "获取query请求体映射内容含义")
    @GetMapping("/mapInfo/{tableId}")
    public Result<Map<String,String>> getTableHeaderQueryInfo(@PathVariable("tableId") String tableId) throws Exception{
        ExcelCreateInfo excelCreateInfo = excelCreateInfoMapper.selectById(tableId);
        String property = (String) excelCreateInfo.getProperty();

        Map<String,String> parse = (Map<String,String>) JSON.parse(property);

        return Result.success(parse);
    }

}
